working of all pairs shortest path